package com.zrrd.gmall.webAll.controller;

import com.zrrd.gmall.cart.feign.CartFeignClient;
import com.zrrd.gmall.common.result.Result;
import com.zrrd.gmall.model.product.SkuInfo;
import com.zrrd.gmall.product.fegin.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;

@Controller
public class CartController {
    @Autowired
    private CartFeignClient cartFeignClient;
    @Autowired
    private ProductFeignClient productFeignClient;

    //查询购物车
    @RequestMapping("/cart.html")
    public String index(HttpServletRequest request){
        return "cart/index";
    }

    //添加购物车
    @RequestMapping("/addCart.html")
    public String addCart(@PathParam("skuId") Long skuId,
                          @PathParam("skuNum") Integer skuNum,
                          HttpServletRequest request) {
        cartFeignClient.addToCart(skuId,skuNum);
        //渲染前端用的数据
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
        //存入请求域中
        request.setAttribute("skuInfo",skuInfo);
        request.setAttribute("skuNum",skuNum);
        //跳转页面
        return "cart/addCart";

    }
}
